package cn.liberals.system.controller;

import cn.liberals.basic.annotation.PreAuthorize;
import cn.liberals.basic.utils.AjaxResult;
import cn.liberals.basic.utils.PageList;
import cn.liberals.system.domain.Dictionarydetail;
import cn.liberals.system.query.DictionarydetailQuery;
import cn.liberals.system.service.IDictionarydetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @Description: 部门的接口类
* @Author: Mr.She
* @Version: 1.0
* @Date:  2022/6/24 10:10
*/
@RestController
@RequestMapping("/dictionaryDetail")
@Api(value = "部门的API",description="部门相关的CRUD功能")
public class DictionarydetailController {

    @Autowired
    private IDictionarydetailService dictionarydetailService;

   /* 
   * @Title: loadById
   * @Description: 通过ID查询
   * @Author: liberals
   * @Version: 1.0
   * @Date:  2022/6/26 15:22  
   * @Parameters: 
   * @Return 
   */
    @GetMapping("/{id}") // 请求地址：http://localhost:8080/dictionarydetail/1 GET请求
    @ApiOperation(value = "通过ID查询" )
    public Dictionarydetail loadById(@ApiParam(value="部门表的主键",required = true) @PathVariable("id") Long id){
        return dictionarydetailService.loadById(id);
    }

    /**
    * @Title: loadAll
    * @Description: 查找所有
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:23  
    * @Parameters: 
    * @Return 
    */
    @GetMapping// 请求地址：http://localhost:8080/dictionarydetail GET请求
    public List<Dictionarydetail> loadAll(){
        return dictionarydetailService.loadAll();
    }

    /*
    * @Title: remove
    * @Description: 删除
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:26
    * @Parameters:
    * @Return
    */
    @DeleteMapping("/{id}") // 请求地址：http://localhost:8080/dictionarydetail/1 GET请求
    public AjaxResult remove(@PathVariable("id") Long id){
        try {
            dictionarydetailService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }


    /*
    * @Title: addOrUpt
    * @Description: 新增或修改
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:26
    * @Parameters:
    * @Return
    */
    @PutMapping
    public AjaxResult addOrUpt(@RequestBody Dictionarydetail dictionarydetail){
        try {
            if(dictionarydetail.getId() == null){
                dictionarydetailService.save(dictionarydetail);
            } else {
                dictionarydetailService.update(dictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }



    /*
    * @Title: queryData
    * @Description: 分页查询+高级查询
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:24
    * @Parameters:
    * @Return
    */
    @PostMapping
    public PageList<Dictionarydetail> queryData(@RequestBody DictionarydetailQuery dictionarydetailQuery){
        PageList<Dictionarydetail> data = dictionarydetailService.queryData(dictionarydetailQuery);
        return data;
    }


    /*
    * @Title: batchDel
    * @Description: 批量删除
    * @Author: liberals
    * @Version: 1.0
    * @Date:  2022/6/26 15:26
    * @Parameters:
    * @Return
    */
    @PatchMapping
    public AjaxResult batchDel(@RequestBody List<Long> ids){
        try {
            dictionarydetailService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统繁忙，请重试！");
        }
    }

}
